home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_multifile.py < prev    next >
Text File  |  2005-11-19  |  2KB  |  67 lines

  1. import mimetools
  2. import multifile
  3. import cStringIO
  4.  
  5. msg = """Mime-Version: 1.0
  6. Content-Type: multipart/mixed;
  7.         boundary="=====================_590453667==_"
  8. X-OriginalArrivalTime: 05 Feb 2002 03:43:23.0310 (UTC) FILETIME=[42D88CE0:01C1ADF7]
  9.  
  10. --=====================_590453667==_
  11. Content-Type: multipart/alternative;
  12.         boundary="=====================_590453677==_.ALT"
  13.  
  14. --=====================_590453677==_.ALT
  15. Content-Type: text/plain; charset="us-ascii"; format=flowed
  16.  
  17. test A
  18. --=====================_590453677==_.ALT
  19. Content-Type: text/html; charset="us-ascii"
  20.  
  21. <html>
  22. <b>test B</font></b></html>
  23.  
  24. --=====================_590453677==_.ALT--
  25.  
  26. --=====================_590453667==_
  27. Content-Type: text/plain; charset="us-ascii"
  28. Content-Disposition: attachment; filename="att.txt"
  29.  
  30. Attached Content.
  31. Attached Content.
  32. Attached Content.
  33. Attached Content.
  34.  
  35. --=====================_590453667==_--
  36.  
  37. """
  38.  
  39. boundaries = 0
  40. linecount = 0
  41.  
  42. def getMIMEMsg(mf):
  43.     global boundaries, linecount
  44.     msg = mimetools.Message(mf)
  45.  
  46.     #print "TYPE: %s" % msg.gettype()
  47.     if msg.getmaintype() == 'multipart':
  48.         boundary = msg.getparam("boundary")
  49.         boundaries += 1
  50.  
  51.         mf.push(boundary)
  52.         while mf.next():
  53.             getMIMEMsg(mf)
  54.         mf.pop()
  55.     else:
  56.         lines = mf.readlines()
  57.         linecount += len(lines)
  58.  
  59. def test_main():
  60.     f = cStringIO.StringIO(msg)
  61.     getMIMEMsg(multifile.MultiFile(f))
  62.     assert boundaries == 2
  63.     assert linecount == 9
  64.  
  65. if __name__ == '__main__':
  66.     test_main()
  67.